/*
 * Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.lingyangwl.agile.pay.pay.model.bo;

import cn.lingyangwl.agile.pay.pay.model.params.IsvParams;
import cn.lingyangwl.framework.tool.core.exception.Assert;
import cn.lingyangwl.agile.pay.constant.IfCodeEnum;
import cn.lingyangwl.agile.pay.model.entity.IsvInfo;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Isv支付参数信息 放置到内存， 避免多次查询操作
 *
 * @author shenguanyang
 */
@Data
public class IsvConfigContext {

    /**
     * isv信息缓存
     */
    private String isvNo;
    private IsvInfo isvInfo;

    /**
     * 商户支付配置信息缓存
     */
    private Map<IfCodeEnum, IsvParams> isvParamsMap = new HashMap<>();

    private Map<IfCodeEnum, IClientWrapper> clientWrapperMap = new ConcurrentHashMap<>();


//    /** 缓存支付宝client 对象 **/
//    private AlipayClientWrapper alipayClientWrapper;
//
//    /** 缓存 wxServiceWrapper 对象 **/
//    private WxServiceWrapper wxServiceWrapper;

    public void addClientWrapper(IfCodeEnum ifCodeEnum, IClientWrapper clientWrapper) {
        Assert.notNull(ifCodeEnum, "ifCodeEnum is null");
        clientWrapperMap.put(ifCodeEnum, clientWrapper);
    }

    public IClientWrapper getClientWrapper(IfCodeEnum ifCodeEnum) {
        return clientWrapperMap.get(ifCodeEnum);
    }

    /**
     * 获取isv配置信息
     */
    public IsvParams getIsvParamsByIfCode(IfCodeEnum ifCode) {
        return isvParamsMap.get(ifCode);
    }
}
